package com.corning.aftersystem.config;

import com.alibaba.fastjson.JSON;

import com.corning.common.exception.RRException;
import com.corning.common.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@Slf4j
public class CorningMedicalException {

    @ResponseBody
    @ExceptionHandler(value = Exception.class)
    public R utecoMallException(Exception e){
        e.printStackTrace();
        if (e instanceof RRException){
            RRException rr=(RRException)e;
            log.info("错误结果："+ JSON.toJSONString(R.error(rr.getCode(),rr.getMsg())));
            return R.error(rr.getCode(),rr.getMsg());
        }
        log.info("异常处理",e);
        return  R.error(e.getMessage());
    }
}
